from Common.do_mysql import DoMysql


class GetSqlObject(object):

    #__instance = None
    __instances = {}

    def __init__(self,cmdopt):
        # if GetSqlObject.__instance is not None:
        #     raise Exception("This class is a singleton!")
        # self.do_mysql = DoMysql(cmdopt).databases()
        # GetSqlObject.__instance = self
        self.do_mysql = DoMysql(cmdopt).databases()

    @staticmethod
    def get_instance(cmdopt):
        # if GetSqlObject.__instance is None:
        #     GetSqlObject.__instance = GetSqlObject(cmdopt)
        # return GetSqlObject.__instance.do_mysql
        if cmdopt not in GetSqlObject.__instances:
            GetSqlObject.__instances[cmdopt] = GetSqlObject(cmdopt)
        return GetSqlObject.__instances[cmdopt].do_mysql


if __name__ == "__main__":
    print(GetSqlObject.get_instance("PRO"))
    print(GetSqlObject.get_instance("test"))